/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.repository.repository.nestedrepository;

import com.inspur.edp.caf.generator.BaseGenerator;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.cef.generator.repository.RepositoryGenContext;
import com.inspur.edp.cef.generator.repository.dac.DataTypeDacGenerator;
import com.inspur.edp.cef.generator.repository.dac.UdtDacGenerator;
import com.inspur.edp.cef.generator.repository.repository.method.GetDacMethodGenerator;
import com.inspur.edp.cef.repository.repo.BaseNestedRepository;

import java.util.ArrayList;

public abstract class NestedRepositoryGenerator extends DataTypeRepositoryGenerator
{
	private static final String DacFieldName = "nestedDac";
	public NestedRepositoryGenerator(RepositoryGenContext parentContext)
	{
		super(parentContext);
	}
	@Override
	protected TypeInfo setParentClass()
	{
		return new TypeInfo(BaseNestedRepository.class.getTypeName());
	}

	@Override
	protected ArrayList<TypeInfo> addParentInterfaces() {
		return super.addParentInterfaces();
	}

	@Override
	protected GetDacMethodGenerator getDacMethodGenerator()
	{
		return new GetNestedDacMethodGenerator(DacFieldName, getDataTypeRepoGenContext());
	}

	@Override
	protected java.util.ArrayList<BaseGenerator> createClassExtendChildGenrators()
	{
		return new java.util.ArrayList<BaseGenerator>(java.util.Arrays.asList(new BaseGenerator[] { getMainDacGenerator() }));
	}

	private DataTypeDacGenerator getMainDacGenerator()
	{
		return getUdtDacGenerator();
	}

	protected abstract UdtDacGenerator getUdtDacGenerator();

	@Override
	protected DataTypeReposGenContext getDataTypeRepoGenCtx()
	{
		return new NestedRepositoryGenCtx();
	}

	@Override
	protected java.util.ArrayList<ClassMethodGenerator> createMethodGenerators()
	{

		ArrayList<ClassMethodGenerator> list = super.createMethodGenerators();
		if (list == null)
		{
			list = new java.util.ArrayList<ClassMethodGenerator>();
		}
		list.add(getMgrMethodGenerator());
		return list;
	}

	protected abstract GetManagerMethodGenerator getMgrMethodGenerator();
}
